package com.xingda.packing.config.appset;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * 读取信息中心接口的配置
 *
 * @author LEGION
 */
@Slf4j
public class AppSetUrl extends JSONObject implements IAppSet {
    private static final long serialVersionUID = 1L;
    //请求接口的IP和端口
    public static String url = "http://172.16.25.93";
    // 中筒层装箱接口
    public static String package_save_url = url + "/xd/api/sctm2/pack/packinglist/save";
    // 查询装箱计划
    public static String packing_plan_url = url + "/xd/api/sctm2/pack/packorder/list";
    // 查询中筒列表
    public static String packing_list_url = url + "/xd/api/sctm2/pack/packing/list";
    // 查询检验方案
    public static String packing_check_url = url + "/xd/api/sctm2/inspectionplan/inspectionplanb/list";
    // 查询中筒详情
    public static String packing_tube_url = url + "/xd/api/sctm2/pack/packing";
    // 包装物信息上传接口
    public static String pack_packinvweigh_url = url + "/xd/api/sctm2/pack/packinvweigh/save";
    // 获取token接口
    public static String token_url = url + "/xd/api/person/singleuser/getToken";
    //查询工字轮信息
    public static String wheel_url = url + "/xd/api/sctm2/intermediate/queryIntermediateVO";
    //查询扭转值
    public static String wheel_torsion_url = url + "/xd/api/sctm2/bd/defdoc/findById";
    //微信登录
    public static String wx_login_url = url + "/desktop/app/pda/wxlogin";
    //卸轮扭转
    public static String down_wheel_url = "http://172.16.126.107:30000/api/downWheel/query";

    @Override
    public void init() {
        log.info("------------------加载AppSetUrl配置------------------");

        String url_init = this.getString("url");
        if (Objects.nonNull(url_init)) {
            url = url_init;
        }
        log.info("请求接口的IP和端口：{}", url);

        String package_save_url_init = this.getString("package_save_url");
        if (Objects.nonNull(package_save_url_init)) {
            package_save_url = getCompleteUrl(package_save_url_init);
        }
        log.info("中筒层装箱接口：{}", package_save_url);

        String packing_plan_url_init = this.getString("packing_plan_url");
        if (Objects.nonNull(packing_plan_url_init)) {
            packing_plan_url = getCompleteUrl(packing_plan_url_init);
        }
        log.info("查询装箱计划：{}", packing_plan_url);

        String packing_list_url_init = this.getString("packing_list_url");
        if (Objects.nonNull(packing_list_url_init)) {
            packing_list_url = getCompleteUrl(packing_list_url_init);
        }
        log.info("查询中筒列表：{}", packing_list_url);

        String packing_check_url_init = this.getString("packing_check_url");
        if (Objects.nonNull(packing_check_url_init)) {
            packing_check_url = getCompleteUrl(packing_check_url_init);
        }
        log.info("查询检验方案：{}", packing_check_url);

        String packing_tube_url_init = this.getString("packing_tube_url");
        if (Objects.nonNull(packing_tube_url_init)) {
            packing_tube_url = getCompleteUrl(packing_tube_url_init);
        }
        log.info("查询中筒详情：{}", packing_tube_url);

        String pack_packinvweigh_url_init = this.getString("pack_packinvweigh_url");
        if (Objects.nonNull(pack_packinvweigh_url_init)) {
            pack_packinvweigh_url = getCompleteUrl(pack_packinvweigh_url_init);
        }
        log.info("包装物信息上传接口：{}", pack_packinvweigh_url);

        String token_url_init = this.getString("token_url");
        if (Objects.nonNull(token_url_init)) {
            token_url = getCompleteUrl(token_url_init);
        }
        log.info("获取token接口：{}", token_url);

        String wheel_url_init = this.getString("wheel_url");
        if (Objects.nonNull(wheel_url_init)) {
            wheel_url = getCompleteUrl(wheel_url_init);
        }
        log.info("查询工字轮信息：{}", wheel_url);

        String wheel_torsion_url_init = this.getString("wheel_torsion_url");
        if (Objects.nonNull(wheel_torsion_url_init)) {
            wheel_torsion_url = getCompleteUrl(wheel_torsion_url_init);
        }
        log.info("查询扭转值：{}", wheel_torsion_url);

        String wx_login_url_init = this.getString("wx_login_url");
        if (Objects.nonNull(wx_login_url_init)) {
            wx_login_url = getCompleteUrl(wx_login_url_init);
        }
        log.info("微信登录接口：{}", wx_login_url);
        String down_wheel_url_init = this.getString("down_wheel_url");
        if (Objects.nonNull(down_wheel_url_init)) {
            down_wheel_url = "http://172.16.126.107:30000/api/downWheel/query";
        }
        log.info("卸轮接口：{}", down_wheel_url);
    }

    private static String getCompleteUrl(String tailUrl) {
        return url + tailUrl;
    }

}
